<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="box">hello world</div>
    <div class="box">hello world</div>
    <div class="box">hello world</div>
    <div class="box">hello world</div>
    <div class="box">hello world</div>
    <div class="box">hello world</div>
    <div class="box">hello world</div>
    <div class="box">hello world</div>

    <script src="../lib/jquery.js"></script>
    <script>

        // const boxes = document.querySelectorAll('.box');

        // boxes.forEach((box, i) => {
        //     box.addEventListener('click', function () {
        //         boxes.forEach((box, j) => {
        //             if (i !== j) {
        //                 box.setAttribute('style', 'color: black');
        //             }
        //         });
        //         this.setAttribute('style', 'color: red');
        //     });
        // });



        // console.log($('.box'));

        $('.box').on('click', function (e) {
            // console.log($(this).index());
            // 选中自己的兄弟
            $(this).siblings().css({ color: 'black' });
            $(this).css({ color: 'red' });
        });



    </script>

</body>
</html>